from decimal import *
import sys
rasp_final=""
c=int(input())
for i in range(0,c):
a,b,c=list(map(int,input().split()))
d,e,f=list(map(int,input().split()))
suma=0
minimul=min(c,e)
suma+=minimul*2
c-=minimul
e-=minimul
minimul=min(c,f)
c-=minimul
f-=minimul
minimul=min(a,f)
a-=minimul
f-=minimul
minimul=min(a,e)
a-=minimul
e-=minimul
minimul=min(a,d)
a-=minimul
d-=minimul
minimul=min(b,e)
b-=minimul
e-=minimul
minimul=min(b,d)
b-=minimul
d-=minimul
minimul=min(c,f)
c-=minimul
f-=minimul
suma+=-2*(min(f,b))
print(suma)
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
void solve(){
ll x1 , y1 , z1 , x2 , y2 , z2 ;
cin >> x1 >> y1 >> z1 ;
cin >> x2 >> y2 >> z2 ;
ll answer = 0 ;
ll t = min(x1 , z2) ;
x1 -= t ;
z2 -= t;
t = min(z1,y2) ;
answer += (t * 2) ;
z1 -= t ;
y2 -= t ;
t = min(z1,z2) ;
z2 -= t ;
z1 -= t ;
answer -= (z2 * 2) ;
cout << answer << endl ;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--){
solve();
}
}
236A - Boy or Girl | 271A - Beautiful Year |
520B - Two Buttons | 231A - Team |
479C - Exams | 1030A - In Search of an Easy Problem |
158A - Next Round | 71A - Way Too Long Words |
160A - Twins | 1A - Theatre Square |
1614B - Divan and a New Project | 791A - Bear and Big Brother |
1452A - Robot Program | 344A - Magnets |
96A - Football | 702B - Powers of Two |
1036A - Function Height | 443A - Anton and Letters |
1478B - Nezzar and Lucky Number | 228A - Is your horseshoe on the other hoof |
122A - Lucky Division | 1611C - Polycarp Recovers the Permutation |
432A - Choosing Teams | 758A - Holiday Of Equality |
1650C - Weight of the System of Nested Segments | 1097A - Gennady and a Card Game |
248A - Cupboards | 1641A - Great Sequence |
1537A - Arithmetic Array | 1370A - Maximum GCD |